import { get, post } from "./request";

/**
 * 获取学生个人信息（包括姓名、积分等）
 */
export function getStudentProfile(studentId) {
    return get('/api/student/info/get', {
        studentId
    });
}

/**
 * 学生登录
 * @param {string} username
 * @param {string} password
 */
export function login(username, password) {
    return post('/api/student/login', {
        username,
        password
    });
}

/**
 * 学生退出登录
 */
export function logout() {
    return post('/api/student/logout', {});
}

/**
 * 根据学生ID获取详细信息
 */
export function getStudentInfo(studentId) {
    return post('/api/student/get', {
        id: studentId
    });
}
/**
  * 获取学生总积分
 * */
export function getStudentTotalPoint(studentId) {
        return post('/api/student-score/total', {
            studentId
        });

}
/**
 * 获取学生参与的活动记录
 */
export function getStudentActivities(studentId) {
    return post('/api/activity-history/student', {
        studentId
    })
}

export function deleteActivityHistoryById(id) {
    return new Promise((resolve, reject) => {
        const token = uni.getStorageSync("accessToken");
        const tokenType = uni.getStorageSync("tokenType") || "Bearer";

        uni.request({
            url: `/api/activity-history/delete/${id}`,
            method: 'DELETE',
            header: {
                'Authorization': token ? `${tokenType} ${token}` : ''
            },
            success: (res) => {
                if (res.statusCode === 200 && res.data.code === 0) {
                    resolve(res.data.data);
                } else {
                    reject(res.data.msg || '删除失败');
                }
            },
            fail: (err) => {
                reject(err);
            }
        });
    });
}


